//===--- UnicodeExtendedGraphemeClusters.cpp.gyb ----------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Runtime/Config.h"

%{

# FIXME: this table should be moved to a Swift file in stdlib.  Unfortunately,
# in Swift we don't have a way to statically initialize arrays.

from GYBUnicodeDataUtils import GraphemeClusterBreakPropertyTable, UnicodeTrieGenerator, get_extended_grapheme_cluster_rules_matrix

grapheme_cluster_break_property_table = \
    GraphemeClusterBreakPropertyTable(unicodeGraphemeBreakPropertyFile)

trie_generator = UnicodeTrieGenerator()
trie_generator.create_tables()
trie_generator.fill_from_unicode_property(grapheme_cluster_break_property_table)
trie_generator.verify(grapheme_cluster_break_property_table)

}%

/// Before compression:
/// bmp_lookup:   ${len(trie_generator.bmp_lookup)}
/// bmp_data:     ${len(trie_generator.bmp_data)} x ${len(trie_generator.bmp_data[0])}
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
/// supp_data:    ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}

%{

trie_generator.freeze()
trie_generator.verify(grapheme_cluster_break_property_table)

}%

/// After compression:
/// bmp_lookup:   ${len(trie_generator.bmp_lookup)}
/// bmp_data:     ${len(trie_generator.bmp_data)} x ${len(trie_generator.bmp_data[0])}
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
/// supp_data:    ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}

%{

trie_generator.serialize(grapheme_cluster_break_property_table)

}%

#include <stdint.h>

static const uint8_t _swift_stdlib_GraphemeClusterBreakPropertyTrieImpl[] = {
% for byte in trie_generator.trie_bytes:
  ${byte},
% end
};

SWIFT_RUNTIME_STDLIB_INTERFACE
extern "C"
const uint8_t *_swift_stdlib_GraphemeClusterBreakPropertyTrie =
    _swift_stdlib_GraphemeClusterBreakPropertyTrieImpl;

struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy {
  unsigned BMPFirstLevelIndexBits;
  unsigned BMPDataOffsetBits;
  unsigned SuppFirstLevelIndexBits;
  unsigned SuppSecondLevelIndexBits;
  unsigned SuppDataOffsetBits;

  unsigned BMPLookupBytesPerEntry;
  unsigned BMPDataBytesPerEntry;
  unsigned SuppLookup1BytesPerEntry;
  unsigned SuppLookup2BytesPerEntry;
  unsigned SuppDataBytesPerEntry;

  unsigned TrieSize;

  unsigned BMPLookupBytesOffset;
  unsigned BMPDataBytesOffset;
  unsigned SuppLookup1BytesOffset;
  unsigned SuppLookup2BytesOffset;
  unsigned SuppDataBytesOffset;
};

SWIFT_RUNTIME_STDLIB_INTERFACE
extern "C" const struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy
_swift_stdlib_GraphemeClusterBreakPropertyTrieMetadata = {
  ${trie_generator.bmp_first_level_index_bits},
  ${trie_generator.bmp_data_offset_bits},
  ${trie_generator.supp_first_level_index_bits},
  ${trie_generator.supp_second_level_index_bits},
  ${trie_generator.supp_data_offset_bits},

  ${trie_generator.bmp_lookup_bytes_per_entry},
  ${trie_generator.bmp_data_bytes_per_entry},
  ${trie_generator.supp_lookup1_bytes_per_entry},
  ${trie_generator.supp_lookup2_bytes_per_entry},
  ${trie_generator.supp_data_bytes_per_entry},

  ${len(trie_generator.trie_bytes)},

  ${trie_generator.bmp_lookup_bytes_offset},
  ${trie_generator.bmp_data_bytes_offset},
  ${trie_generator.supp_lookup1_bytes_offset},
  ${trie_generator.supp_lookup2_bytes_offset},
  ${trie_generator.supp_data_bytes_offset},
};

%{

extended_grapheme_cluster_rules_matrix = \
    get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table)

}%


static const uint16_t _swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl[] = {
% for row in get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table):
  ${row},
% end
};

extern "C"
SWIFT_RUNTIME_STDLIB_INTERFACE
const uint16_t *_swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrix =
    _swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl;

// ${'Local Variables'}:
// eval: (read-only-mode 1)
// End:
